/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uca.sisbec.helpers.manto;

import com.uca.sisbec.forms.manto.AgendaReunionForm;
import com.uca.sisbec.mapping.AgendaXReunion;
import com.uca.sisbec.mapping.AgendaXReunionId;
import com.uca.sisbec.mapping.Reunion;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;


/**
 *
 * @author Alex
 */
public class AgendaReunionHelper {
    private Session session;
    
    public AgendaReunionHelper(Session session){
        this.session=session;
    }
    
    public Reunion InsertarPuntoAgendaDB(AgendaReunionForm arf){
        AgendaXReunionId arxid = new AgendaXReunionId();
        arxid.setCorrelPtoAgenda(arf.getCorrelPtoAgenda());
        arxid.setIdReunion(arf.getIdReunion());
        AgendaXReunion axr = new AgendaXReunion();
        axr.setId(arxid);
        axr.setPuntoAgenda(arf.getPuntoAgenda());
        session.save(axr);
        return axr.getReunion();
    }
    
    public boolean ExistePuntoAgendaSimilarDB(AgendaReunionForm arf){
        Criteria crit = session.createCriteria(AgendaXReunion.class);
        crit = crit.add(Expression.like("puntoAgenda",arf.getPuntoAgenda()));
        List<AgendaXReunion> listAgendaReu = new ArrayList<AgendaXReunion>(crit.list());
        if(listAgendaReu.size() > 0){
            return true;
        }else{
            return false;
        }
    }
    
    public void EliminarPuntoAgendaDB(int idReu, int idPtoAgenda){
        AgendaXReunionId arxid = new AgendaXReunionId();
        arxid.setIdReunion(idReu);
        arxid.setCorrelPtoAgenda(idPtoAgenda);
        AgendaXReunion axr = new AgendaXReunion();
        axr.setId(arxid);
        session.load(axr, arxid);
        session.delete(axr);
    }
    
}
